package com.example.demospringboot.controller.depcontroller;


import com.example.demospringboot.domains.Department;
import com.example.demospringboot.domains.Employee;
import com.example.demospringboot.mapper.DepartmentMapper;
import com.example.demospringboot.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    DepartmentMapper deptMapper;

	@Autowired
    EmployeeMapper empMapper;

    @GetMapping("/dept/{deptCode}")
    public Department getDepartmentByCode(@PathVariable String deptCode){
        Department dept = deptMapper.getDepartmentByDeptCode(deptCode);
        return dept;
    }


    @GetMapping("/{deptCode}")
    public List<Employee> getEmployeeByDeptCode(@PathVariable String deptCode){
        return empMapper.getEmployeeByDeptCode(deptCode);
    }
}
